package com.etmvc.controller.auth;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import com.et.mvc.JsonView;
import com.et.mvc.util.Json;
import com.etmvc.core.AuthName;
import com.etmvc.core.ManageController;
import com.etmvc.service.auth.SpaceService;
import com.etmvc.tools.AuthUtils;

@AuthName("管理中心")
public class SpaceController extends ManageController {
	SpaceService service = new SpaceService();
	@AuthName("管理中心首页")
	public void index(){
		
	}
	@AuthName(value="后台地址管理",menu=true)
	public void allUrls(){
//		String authBasePath = servletContext.getInitParameter("authBasePath");
//		Map<String,List<String>> allUrls = AuthUtils.getAllUrls(authBasePath);
//		request.setAttribute("urls", allUrls);
	}
	@AuthName("获取菜单挂载的地址")
	public JsonView getMenuUrlsJson() {
		String authBasePath = servletContext.getInitParameter("authBasePath");
		List<Map<String, Object>> records = service.getMenuUrlsTreeData(authBasePath);
		return new JsonView(records);
	}
	@AuthName("获取所有后台地址")
	public JsonView getAllUrlsJson(){
		String authBasePath = servletContext.getInitParameter("authBasePath");
		Map<String, Object> root = new HashMap<String, Object>();
		List<Map<String, Object>> records = service.getAllUrlsTreeData(authBasePath);
		root.put("text", "管理后台URL");
		root.put("children", records.toArray());
		return new JsonView(new Object[]{root});
	}
}
